/**
 * Created by oneminute on 7/18/14.
 */

var assert = require("assert");
var should = require("should");
var logger = require("../../lib/utils/logger");
var testutils = require("../testutils");
var lz = require("../../lib/utils/modules")();

describe("测试Issue模块。", function () {
    var issue01 = null;

    it("正常创建Issue对象。", function (done) {
        issue01 = new lz.Issue({
            id: lz.Utils.getUUID("i_"),
            uid: "u_test0001",
            title: "测试问题标题",
            content: "测试提交问题内容"
        });
        issue01.save(function (_err, _issue) {
            testutils.check(done, function () {
                _issue.uid.should.equal(issue01.uid);
                assert.notEqual(_issue._id, null);
            });
        });
    });

    it("根据_id正常加载Issue对象。", function (done) {
        var issue02 = new lz.Issue({_id: issue01._id});
        issue02.load(function(_err, _issue) {
            testutils.check(done, function () {
                issue02.uid.should.equal(issue01.uid);
            });
        });
    });

    it("根据AQL正常加载Issue对象。", function (done) {
        var issue03 = new lz.Issue();
        issue03.load({method: "byProp", prop: "uid", value: issue01.uid}, function(_err, _issue) {
            testutils.check(done, function() {
                issue03.uid.should.equal(issue01.uid);
            });
        });
    });

    it("根据uid使用list方法正常列出Issue对象。", function (done) {
        var issue04 = new lz.Issue({uid: issue01.uid});
        issue04.list({method: "byProp", prop: "uid"}, function(_err, _commodities) {
            testutils.check(done, function() {
                assert.equal(_commodities.length > 0, true);
                lz.Logger.info("commodities: ", _commodities);
            });
        });
    });

    it("使用delete方法删除Issue对象。", function (done) {
        issue01.delete(function(_err){
            lz.ArangoDB.getObjectById(issue01._id, function(_err, _obj) {
                testutils.check(done, function() {
                    assert.equal(_obj, null);
                });
            });
        });
    });

    after(function(done) {
        /*lz.ArangoDB.deleteObjectById(email01._id, function() {
            done();
        });*/
        done();
    });
});
